package com.dkd.applet.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dkd.applet.domain.Channel;
import com.dkd.applet.mapper.ChannelMapper;
import com.dkd.applet.service.ChannelService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, Channel> implements ChannelService {

    @Override
    public Channel getChanneleByInnerCodeAndSku(String innerCode, Long skuId) {
        // 构建查询条件
        LambdaQueryWrapper<Channel> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Channel::getInnerCode, innerCode)
                .eq(Channel::getSkuId, skuId)
                .gt(Channel::getCurrentCapacity, 0);
        // 执行查询并返回结果
        List<Channel> channelList = this.list(queryWrapper);
        if (channelList != null && !channelList.isEmpty()) {
            return channelList.get(0);
        }
        return null;
    }

    @Override
    public Channel getChanneleByInnerCodeAndChannelCode(String innerCode, String channelCode) {
        // 构建查询条件
        LambdaQueryWrapper<Channel> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Channel::getInnerCode, innerCode)
                .eq(Channel::getChannelCode, channelCode)
                .gt(Channel::getCurrentCapacity, 0);
        return this.getOne(queryWrapper);
    }
}
